package com.hethongviet.job.helpers;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

import com.hethongviet.job.models.Comment;
import com.hethongviet.job.models.Project;
import com.hethongviet.job.models.Task;

public final class ComparableHelper
{
	public static class ProjectCompartorByNameUp implements Comparator<Project>
	{
		public int compare(Project one, Project another)
		{
			return one.getName().compareTo(another.getName());
		}
	}

	public static class ProjectCompartorByNameDown implements
			Comparator<Project>
	{
		public int compare(Project one, Project another)
		{
			return (-1) * one.getName().compareTo(another.getName());
		}
	}

	public static class ProjectCompartorByWorkerUp implements
			Comparator<Project>
	{
		public int compare(Project one, Project another)
		{
			return one.getWorker().compareTo(another.getWorker());
		}
	}

	public static class ProjectCompartorByWorkerDown implements
			Comparator<Project>
	{
		public int compare(Project one, Project another)
		{
			return (-1) * one.getWorker().compareTo(another.getWorker());
		}
	}

	public static class ProjectCompartorByDateCreateUp implements
			Comparator<Project>
	{
		public int compare(Project one, Project another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateCreated());
				Date dateAnothor = dateFormat.parse(another.getDateCreated());
				return dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class ProjectCompartorByDateCreateDown implements
			Comparator<Project>
	{
		public int compare(Project one, Project another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateCreated());
				Date dateAnothor = dateFormat.parse(another.getDateCreated());
				return (-1) * dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByCodeUp implements Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			return one.getCode().compareTo(another.getCode());
		}
	}

	public static class TaskCompartorByCodeDown implements Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			return (-1) * one.getCode().compareTo(another.getCode());
		}
	}

	public static class TaskCompartorByDateActualFinishUp implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateActualFinish());
				Date dateAnothor = dateFormat.parse(another.getDateActualFinish());
				return dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateActualFinishDown implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateActualFinish());
				Date dateAnothor = dateFormat.parse(another.getDateActualFinish());
				return (-1) * dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateActualStartUp implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateActualStart());
				Date dateAnothor = dateFormat.parse(another.getDateActualStart());
				return dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateActualStartDown implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateActualStart());
				Date dateAnothor = dateFormat.parse(another.getDateActualStart());
				return (-1) * dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateRequireFinishUp implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateRequireFinish());
				Date dateAnothor = dateFormat.parse(another.getDateRequireFinish());
				return dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateRequireFinishDown implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateRequireFinish());
				Date dateAnothor = dateFormat.parse(another.getDateRequireFinish());
				return (-1) * dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateRequireStartUp implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateRequireStart());
				Date dateAnothor = dateFormat.parse(another.getDateRequireStart());
				return dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByDateRequireStartDown implements
			Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateRequireStart());
				Date dateAnothor = dateFormat.parse(another.getDateRequireStart());
				return (-1) * dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class TaskCompartorByNameUp implements Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			return one.getName().compareTo(another.getName());
		}
	}

	public static class TaskCompartorByNameDown implements Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			return (-1) * one.getName().compareTo(another.getName());
		}
	}

	public static class TaskCompartorByWorkerUp implements Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			return one.getWorker().compareTo(another.getWorker());
		}
	}

	public static class TaskCompartorByWorkerDown implements Comparator<Task>
	{
		public int compare(Task one, Task another)
		{
			return (-1) * one.getWorker().compareTo(another.getWorker());
		}
	}

	public static class CommentCompartorBySenderUp implements
			Comparator<Comment>
	{
		public int compare(Comment one, Comment another)
		{
			return one.getSender().compareTo(another.getSender());
		}
	}

	public static class CommentCompartorBySenderDown implements
			Comparator<Comment>
	{
		public int compare(Comment one, Comment another)
		{
			return (-1) * one.getSender().compareTo(another.getSender());
		}
	}

	public static class CommentCompartorByDateCreateUp implements
			Comparator<Comment>
	{
		public int compare(Comment one, Comment another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateCreate());
				Date dateAnothor = dateFormat.parse(another.getDateCreate());
				return dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				e.printStackTrace();
			}
			return 0;
		}
	}

	public static class CommentCompartorByDateCreateDown implements
			Comparator<Comment>
	{
		public int compare(Comment one, Comment another)
		{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy kk:mm");
			try
			{
				Date dateOne = dateFormat.parse(one.getDateCreate());
				Date dateAnothor = dateFormat.parse(another.getDateCreate());
				return (-1) * dateOne.compareTo(dateAnothor);
			} catch (ParseException e)
			{
				e.printStackTrace();
			}
			return 0;
		}
	}

}
